{template 'common/header-base'}
<script>
	window.w7.ready(function(){
		window.w7.login(function(evt){
			code = evt.data.code;
			var redirect = '';
			var siteurl = "{$_W['siteurl']}";
			if (siteurl.indexOf('web/index.php?c=account&a=manage&do=display&w7i=0&iscontroller=1') != -1) {
				redirect = encodeURIComponent(siteurl);
			}
			fetch("{php echo $_W['siteroot']}web/index.php?c=user&a=login", {
				method: 'POST',
				headers: {'Content-Type': 'application/x-www-form-urlencoded','X-Requested-With': 'XMLHttpRequest'},
				body: 'code=' + code + '&redirect=' + redirect,
			}).then(response => {
				response.text().then(body => {
					var obj = JSON.parse(body)
					if (0 != obj.message.errno) {
						util.message(obj.message.message, obj.redirect, 'error');
						return false;
					}
					window.location.href = obj.redirect;
					return true;
				});
			});
		});
	})
</script>
